<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>菜单列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">
    <style>
        .layui-table-cell{
            display:table-cell;
            vertical-align: middle;
        }
        .fr .layui-input-inline{
            margin-right: 20px;
            margin-bottom: 10px;
        }
        .layui-tree-txt{
            color: #00C0F7;
        }
         .red-alert {
             background-color: #FF5722;
             color: white;
             padding: 10px 20px;
             border-radius: 5px;
             text-align: center;
             margin-bottom: 20px;
         }
    </style>
</head>
<body style="padding-top: 20px">
<div class="layui-fluid">
    <div class="layui-card" style="padding-bottom: 10px;">
        <div style="font-size: 18px;">
            登录次数：<span style="color: red" id="loginCountId">0</span>&nbsp;&nbsp;&nbsp;
            登录人数：<span style="color: red" id="loginMemberId">0</span>&nbsp;&nbsp;&nbsp;
            查询近&nbsp;
            <div class="layui-input-inline" style="width: 40px;" >
                <input type="text" value="1" min="1" autocomplete="off" name="days" placeholder="" class="layui-input height33">
            </div>
            &nbsp;天&nbsp;&nbsp;&nbsp;
            <button class="layui-btn layui-btn-sm" id="searchLogin">查询</button>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
            注册人数：<span style="color: red" id="registerMemberId">0</span>
            &nbsp;&nbsp;&nbsp;
            <div class="layui-btn-group">
                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="queryRegister(0)">今天</button>
                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="queryRegister(1)">昨天</button>
            </div>
            &nbsp;&nbsp;&nbsp;
            实名人数：<span style="color: red" id="realMemberId">0</span>
            &nbsp;&nbsp;&nbsp;
            <button class="layui-btn layui-btn-danger layui-btn-sm" id="oneTouchUnFreezeId">一键解冻</button>
        </div>

        <!--<div class="layui-btn-group">-->
            <!--<button type="button" onclick="queryLoginToday()" class="layui-btn layui-btn-sm layui-btn-normal">今日</button>-->
            <!--<button type="button" onclick="queryLogin(3)" class="layui-btn layui-btn-sm layui-btn-normal">近3日</button>-->
            <!--<button type="button" onclick="queryLogin(7)" class="layui-btn layui-btn-sm layui-btn-normal">近7日</button>-->
            <!--<button type="button" onclick="queryLoginMonth()" class="layui-btn layui-btn-sm layui-btn-normal">近一月</button>-->
        <!--</div>-->
    </div>
    <div class="layui-card">
        <div class="my-btn-box layui-form">
            <span class="fr">
                <div class="layui-input-inline">
                     <select name="status" id="statusId" lay-filter="state">
                        <option value="">请选择状态开启|关闭</option>
                        <option value="0">正常</option>
                        <option value="1">冻结</option>
                      </select>
                </div>
                <div class="layui-input-inline">
                     <select name="background" id="backgroundId" lay-filter="state">
                        <option value="">请选择真实or后台</option>
                        <option value="0">真实用户</option>
                        <option value="1">后台注册</option>
                      </select>
                </div>
                <div class="layui-input-inline">
                     <select name="authentication" id="authenticationId" lay-filter="state">
                        <option value="">请选择是否实名</option>
                        <option value="0">未实名</option>
                        <option value="1">已实名</option>
                      </select>
                </div>
                <div class="layui-input-inline">
                     <select name="level" id="levelId" lay-filter="state">
                        <option value="">请选择会员类型</option>
                        <option value="0">普通</option>
                        <option value="1">初级合伙人</option>
                        <option value="4">中级合伙人</option>
                        <option value="2">高级合伙人</option>
                        <option value="3">终级合伙人</option>
                      </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="id" placeholder="用户ID" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="name" placeholder="用户昵称" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="realName" placeholder="真实姓名" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="ucode" placeholder="邀请码（自己）" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="recommendCode" placeholder="邀请码（上级）" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="mobile" placeholder="手机号" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="appid" placeholder="应用ID" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="remark" placeholder="备注" class="layui-input height33">
                </div>
                 <div class="layui-input-inline">
                      <input type="text" name="ctime" autocomplete="off" class="layui-input height33" id="ctimeId"  placeholder="创建时间">
                  </div>
                <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i>搜索</button>
            </span>
        </div>
        <div class="layui-card-body" style="margin-top: 40px;">
            <div id="dateTable" lay-filter="event"></div>
            <div class="height50"></div>
        </div>
    </div>
</div>
<!--实名认证编辑-->
<div id="realAuthId" style="display: none;padding: 30px">
    <form class="layui-form" lay-filter="realAuth">
        <input type="hidden" name="userId" lay-verify="userId" autocomplete="off" placeholder="请输入真实姓名" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="realName" lay-verify="realName" autocomplete="off" placeholder="请输入真实姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-block">
                <input type="text" name="idNumber" lay-verify="idNumber" autocomplete="off" placeholder="请输入身份证号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="realAuthSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--冻结编辑-->
<div id="freezeId" style="display: none;padding: 30px">
    <form class="layui-form" lay-filter="freeze">
        <div class="red-alert" id="alterMsgId">
            应设置权重之和为1！
        </div>
        <input type="hidden" name="userId" lay-verify="userId" autocomplete="off" placeholder="" class="layui-input">
        <input type="hidden" name="status" lay-verify="status" autocomplete="off" placeholder="" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 130px" id="lowerId">批量冻结其所有下级</label>
            <div class="layui-input-block">
                <input type="checkbox" name="lowerLevel" lay-skin="switch" lay-text="是|否" id="lowerLevel">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="freezeSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<div id="tree-container" style="display: none;"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">
    var tree;
    // layui方法
    layui.use(['table', 'form', 'element', 'laypage', 'layer', 'tree','laydate'], function () {
        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , laydate = layui.laydate
            , $ = layui.jquery;
        tree = layui.tree

        var element = layui.element;
        var userId = "";
        // 默认查询今天的登录次数和人数
        queryUserLogin();
        // 默认查询今天的注册人数
        queryRegister(0);
        // 查询实名人数
        queryReal();

        // 树形组件配置
        tree.render({
            elem: '#tree-container',
            data: [],  // 树形节点数据
            showLine: false,  // 是否显示连接线
            onlyIconControl: false,  // 是否仅允许点击图标控制展开和折叠
            click: function(node) {
                // 使用 reload 方法重新渲染树形组件
                tree.reload('tree-container', {
                    data: tree.getData('tree-container')  // 使用当前的数据重新渲染
                });
            }
        });

        //创建时间
        var ctime = laydate.render({
            elem: '#ctimeId',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger:'click',
            value: '',
            done: function(value, date){
            }
        });
        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {field: 'id', title: 'ID', minWidth: '100', sort: true, align: 'center'}
                ,{field: 'nick', title: '昵称', minWidth: '100', align: 'center'}
                , {field: 'mobile', title: '手机号', minWidth: '100', align: 'center'}
                , {field: 'avatar', title: '用户头像', minWidth: '50', align: 'center', templet: function (d) {
                        var avatar = d.avatar == null ? '' : d.avatar;
                        return "<a style='margin-left: 5px;' onclick='showUserDetails("+d.id+")'><img src='" + avatar + "' width='40' height='40'  /></a>";
                    }
                }
                , {field: 'realName', title: '真实姓名',minWidth: '100', align: 'center'}
                , {field: 'idNumber', title: '身份证号', minWidth: '200', align: 'center'}
                , {field: 'appid', title: '应用ID', minWidth: '100', align: 'center'}
                , {
                    field: 'loginTime', title: '最近一次登录时间', minWidth: '195', align: 'center', templet: function (d) {
                        var ipStr = "";
                        if (d.ipList != null && d.ipList.length > 0) {
                            for (var i = 0; i < d.ipList.length; i++) {
                                var ip = d.ipList[i].ip;
                                var area = d.ipList[i].area;
                                ipStr += "<span style='color: green' class='layui-badge-rim'> IP:" + ip + "</span>";
                                ipStr += "<span style='color: rebeccapurple' class='layui-badge-rim'> 地区:" + area + "</span>";
                            }
                        }else {
                            ipStr += "暂无数据";
                        }
                        return new Date(d.loginTime == null ? d.ctime : d.loginTime).Format("yyyy-MM-dd hh:mm:ss") +
                            "</br><button class='layui-btn layui-btn-xs loginIP'>显示最近登录IP</button>" +
                            "<div style='display: none;border: 1px solid darkseagreen'>" + ipStr + "</div>";
                    }
                }
                , {
                    field: 'ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    minWidth: '195',
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {field: 'banlance', title: '余额',minWidth: '20', align: 'center'}
                , {field: 'integral', title: '积分', minWidth: '20', align: 'center'}
                , {field: 'level', title: '会员等级',minWidth: '50', align: 'center', templet: function (d) {
                    var type = d.level;
                    if (null == type || 0 == type) {
                        return "<button class='layui-btn layui-btn-primary layui-btn-xs'>普通会员</button>";
                    }
                    if (1 == type) {
                        return "<button class='layui-btn layui-btn-normal layui-btn-xs'>初级合伙人</button>";
                    }
                    if (2 == type) {
                        return "<button class='layui-btn layui-btn-warm layui-btn-xs'>高级合伙人</button>";
                    }
                    if (4 == type) {
                        return "<button class='layui-btn layui-btn-xs'>中级合伙人</button>";
                    }
                    return "<button class='layui-btn layui-btn-danger layui-btn-xs'>终级合伙人</button>";
                }}
                , {field: 'ucode', title: '邀请码(自己)',minWidth: '50', align: 'center', templet: function (d) {
                    var ucode = d.ucode;
                    return "<button onclick=\"showLowerLevel('"+ucode+"');\" class='layui-btn layui-btn-normal layui-btn-xs'>"+ucode+"</button>";
                }}
                , {field: 'recommendCode', title: '邀请码(上级)',minWidth: '50', align: 'center', edit: "text", templet: function (d) {
                        return d.recommendCode + '</br><button class=\'layui-btn layui-btn-danger layui-btn-xs\'>可编辑</button>';
                }}
                , {field: 'remark', title: '备注', minWidth: '100', align: 'center'}
                , {title: '操作', align: 'center', width: '220', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/member/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                // $("td[data-field='content']").each(function () {
                //     $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                // });

                // 查看登录IP
                $(".loginIP").on("click", function () {
                    var ss = $(this).next().css("display");
                    console.log(ss)
                    if (ss == "none") {
                        $(this).next().css("display", "");
                        $(this).text("隐藏最近登录IP");
                    } else {
                        $(this).next().css("display", "none");
                        $(this).text("显示最近登录IP");
                    }
                })


            }
        });

        // 修改实名认证信息
        form.on('submit(realAuthSubmit)', function(data){
            var data = data.field;
            $.ajax({
                type: "post",
                url: [[${basePath}]] + "/member/valid/status",
                data: {
                    userId: data.userId,
                    realName: data.realName || "",
                    idNumber: data.idNumber || ""
                },
                success: function (res) {
                    layer.close(index);
                    if (res.success) {
                        layer.msg("修改实名状态成功！", {icon: 1}, 2000);
                        setTimeout(function () {
                            tableIns.reload();
                        }, 2000);
                    } else {
                        layer.msg(res.msg, {icon: 2}, 2000);
                    }
                }
            });
        });
        // 冻结操作
        form.on('submit(freezeSubmit)', function(data){
            var data = data.field;
            data.lowerLevel = data.lowerLevel === "on" ? "0" : "1";
            $.ajax({
                type: "post",
                url: [[${basePath}]] + "/member/status/updateForLower",
                data: {
                    id: data.userId,
                    status: data.status,
                    lowerLevel: data.lowerLevel
                },
                success: function (res) {
                    layer.close(index);
                    if (res.success) {
                        layer.msg("修改成功！", {icon: 1}, 2000);
                        setTimeout(function () {
                            tableIns.reload();
                        }, 2000);
                    } else {
                        layer.msg(res.msg, {icon: 2}, 2000);
                    }
                }
            });
        });
        // 单元格编辑
        table.on('edit(event)', function(obj){
            var data = obj.data;
            $.ajax({
                type: "post",
                url: [[${basePath}]] + "/member/edit",
                data: {
                    userId: data.id,
                    recommendCode: data.recommendCode
                },
                success: function (res) {
                    if (res.success) {
                        layer.msg("修改成功！", {icon: 1}, 2000);
                    } else {
                        layer.msg("操作失败！", {icon: 2}, 2000);
                    }
                }
            });

        });
        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '添加用户',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/member/save/index'
                    });
                    break;
                case 'groupAuthAll':
                    layer.confirm("确定所有用户拥有建群权限?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/group/auth/all",
                            data: {},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("操作完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });

                    });
                    break;
                case 'groupAuthNone':
                    layer.confirm("确定所有用户没有建群权限?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/group/auth/none",
                            data: {},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("操作完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });

                    });
            }
        });
        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.prompt({
                    formType: 0,
                    value: data.remark,
                    title: '请输入备注信息',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    if (value == null || value == '') {
                        layer.msg("备注信息不能为空", {icon: 6, time: 1500});
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/edit",
                        data: {userId: data.id, remark: value},
                        success: function (res) {
                            layer.close(index);
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 2000);
                                setTimeout(function () {
                                    tableIns.reload()
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });

                // layer.open({
                //     type: 2,
                //     title: '用户详情',
                //     shadeClose: true,
                //     shade: 0.2,
                //     maxmin: true, //开启最大化最小化按钮
                //     area: ['650px', '550px'],
                //     content: [[${basePath}]] + '/member/detail?id=' + data.id
                // });

            }
            // 用户积分
            if (obj.event === 'integral') {
                layer.prompt({
                    formType: 0,
                    value: data.integral,
                    title: '请输入用户积分',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    if (value == null || value == '') {
                        layer.msg("用户积分不能为空", {icon: 6, time: 1500});
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/edit",
                        data: {userId: data.id, integral: value},
                        success: function (res) {
                            layer.close(index);
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 2000);
                                setTimeout(function () {
                                    tableIns.reload()
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });
            }
            // 赠送浇水次数
            if (obj.event === 'water') {
                layer.prompt({
                    formType: 0,
                    value: 0,
                    title: '请输入浇水次数',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    if (value == null || value == '') {
                        layer.msg("浇水次数不能为空", {icon: 6, time: 1500});
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/carbon/plantTree/addNumbers",
                        data: {
                            userId: data.id,
                            num: value
                        },
                        success: function (res) {
                            layer.close(index);
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 2000);
                                setTimeout(function () {
                                    tableIns.reload()
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });
            }
            if (obj.event === 'integralDetails') {
                layer.open({
                    type: 2,
                    title: '积分详情',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1150px', '550px'],
                    content: [[${basePath}]] + '/member/list/integralDetails?userId=' + data.id
                });
            }
            //清除登录token
            if (obj.event === 'delete') {

                layer.confirm("确定删除该用户？", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/clean/login/status",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("清除完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });
                });
            }

            if (obj.event === 'groupAuth') {
                var te = (data.createGroupAuth == null || data.createGroupAuth == 0) ? ("确定给该用户拥有建群权限吗？") : ("确定取消用户拥有建群权限吗？");
                layer.confirm(te, {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                $.ajax({
                    type: "post",
                    url: [[${basePath}]] + "/member/group/auth",
                    data: {userId: data.id, status: data.createGroupAuth == 0 ? 1 : 0},
                    success: function (res) {
                        if (res.success) {
                            layer.msg("权限修改成功！", {icon: 1}, 2000);

                            layer.close(index);

                            setTimeout(function () {
                                tableIns.reload();
                            }, 2000);
                        } else {
                            layer.msg(res.msg, {icon: 2}, 2000);
                        }
                    }
                });
                }, function (index) {
                });
            }
            if (obj.event === 'friend') {
                layer.open({
                    type: 2,
                    title: '好友列表',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['80%', '550px'],
                    content: [[${basePath}]] + '/member/friend/index?id=' + data.id
                });
            }
            // 用户资金明细
            if (obj.event === 'fundDetails') {
                layer.open({
                    type: 2,
                    title: '资金明细',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['80%', '550px'],
                    content: [[${basePath}]] + '/member/fundDetails?userId=' + data.id
                });
            }
            if (obj.event === 'freeze') {
                $("#alterMsgId").text("该操作为永久性的，确定" + (data.status == 0 ? "冻结" : "开启") + "用户状态?");
                $("#lowerId").text("批量" + (data.status == 0 ? "冻结" : "开启") + "其所有下级");
                layer.open({
                    type: 1,
                    title: '冻结',
                    area: ['420px', '275px'],
                    content: $('#freezeId'),
                    success: function () {
                        form.val('freeze', {
                            "userId": data.id,
                            "status": data.status == 0 ? 1 : 0,
                            "lowerLevel": null
                        });
                    }
                });

                // layer.confirm("该操作为永久性的，确定" + (data.status == 0 ? "冻结" : "开启") + "用户状态?", {
                //     icon: 3,
                //     title: '提示'
                // }, function (index) {
                //
                //
                //     // $.ajax({
                //     //     type: "post",
                //     //     url: [[${basePath}]] + "/member/status/update",
                //     //     data: {id: data.id, status: data.status == 0 ? 1 : 0},
                //     //     success: function (res) {
                //     //         if (res.success) {
                //     //             layer.msg(res.msg, {icon: 1}, 500);
                //     //             layer.close(index);
                //     //             tableIns.reload();
                //     //         }
                //     //     }
                //     // });
                // });
            }
            if (obj.event === 'changePassword') {
                layer.confirm("确定修改该用户登录密码?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.prompt({
                        formType: 0,
                        value: '111111',
                        title: '请输入密码',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function (value, index, elem) {
                        if (value == null || value == '') {
                            layer.msg("密码不能为空", {icon: 6, time: 1500});
                            return;
                        }
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/password/change",
                            data: {userId: data.id, password: value},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("登录密码修改成功！", {icon: 1}, 2000);

                                    layer.close(index);

                                    setTimeout(function () {
                                        tableIns.reload();
                                    }, 2000);
                                } else {
                                    layer.msg(res.msg, {icon: 2}, 2000);
                                }
                            }
                        });
                        layer.close(index);
                    });
                }, function (index) {
                });
            }
            if (obj.event === 'changePayPassword') {
                layer.confirm("确定修改该用户支付密码?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.prompt({
                        formType: 0,
                        value: '654321',
                        title: '请输入密码',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function (value, index, elem) {
                        if (value == null || value == '') {
                            layer.msg("密码不能为空", {icon: 6, time: 1500});
                            return;
                        }
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/password/pay/change",
                            data: {userId: data.id, password: value},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("支付密码修改成功！", {icon: 1}, 2000);

                                    layer.close(index);

                                    setTimeout(function () {
                                        tableIns.reload();
                                    }, 2000);
                                } else {
                                    layer.msg(res.msg, {icon: 2}, 2000);
                                }
                            }
                        });
                        layer.close(index);
                    });
                }, function (index) {
                });
            }
            // 聊天记录
            if (obj.event === 'chatRecord') {
                layer.open({
                    type: 2,
                    title: data.nick + '的视角',
                    shadeClose: true,
                    shade: 0.2,
                    // maxmin: true, //开启最大化最小化按钮
                    area: ['1002px', '660px'],
                    content: [[${basePath}]] + '/member/chatRecord/index?userId=' + data.id
                })
            }
            // 修改实名认证
            if (obj.event === 'changeValidStatus') {
                layer.open({
                    type: 1,
                    title: '实名认证',
                    area: ['500px', '270px'],
                    content: $('#realAuthId'),
                    success: function () {
                        form.val('realAuth', {
                            "userId": data.id,
                            "realName": data.realName,
                            "idNumber": data.idNumber
                        });
                    }
                });
            }
        });
        var status = 0;
        form.on('switch(status)', function (data) {
            if (!data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }
            $("#search").click();
        });

        var groupAuth = null;
        form.on('select(groupAuth)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            groupAuth = (data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
        });

        var validStatus = null;
        form.on('select(validStatus)', function (data) {
            validStatus = (data.value); //得到被选中的值
        });

        function getJson() {
            return {
                where: {
                    name: $("input[name='name']").val()
                    ,realName: $("input[name='realName']").val()
                    ,userId: $("input[name='id']").val()
                    ,status: $("#statusId").find("option:selected").val()
                    ,background: $("#backgroundId").find("option:selected").val()
                    ,authentication: $("#authenticationId").find("option:selected").val()
                    ,level: $("#levelId").find("option:selected").val()
                    ,mobile: $("input[name='mobile']").val()
                    ,recommendCode: $("input[name='recommendCode']").val()
                    ,ucode: $("input[name='ucode']").val()
                    ,appid: $("input[name='appid']").val()
                    ,remark: $("input[name='remark']").val()
                    , ctime: $("#ctimeId").val()
                    ,groupStatus: groupAuth
                    ,validStatus: validStatus
                }
            };
        }

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    name: $("input[name='name']").val()
                    ,realName: $("input[name='realName']").val()
                    ,userId: $("input[name='id']").val()
                    ,status: $("#statusId").find("option:selected").val()
                    ,background: $("#backgroundId").find("option:selected").val()
                    ,authentication: $("#authenticationId").find("option:selected").val()
                    ,level: $("#levelId").find("option:selected").val()
                    ,mobile: $("input[name='mobile']").val()
                    ,recommendCode: $("input[name='recommendCode']").val()
                    ,ucode: $("input[name='ucode']").val()
                    ,appid: $("input[name='appid']").val()
                    ,remark: $("input[name='remark']").val()
                    , ctime: $("#ctimeId").val()
                    ,groupStatus: groupAuth
                    ,validStatus: validStatus
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }

            });
        });


        // 查询近xx天的登录人数和次数
        $("#searchLogin").click(function () {
            queryUserLogin();
        });

        // 一键解冻所有用户
        $("#oneTouchUnFreezeId").click(function () {

            layer.confirm("确定一键解冻所有冻结用户?", {
                icon: 3,
                title: '提示'
            }, function (index) {
                $.ajax({
                    type: "post",
                    url: [[${basePath}]] + "/member/oneTouchUnFreezeAll",
                    data: {},
                    success: function (res) {
                        if (res.success) {
                            var data = res.data;
                            if (data.length == 0) {
                                layer.msg("解冻成功！", {icon: 1}, 2000);
                                return
                            }
                            layer.msg(data);
                        } else {
                            layer.msg(res.msg, {icon: 1}, 2000);
                        }
                    }
                });
            }, function (index) {
            });
        });
    });

    // 展示下级用户
    function showLowerLevel(ucode) {
        $.ajax({
            type: "post",
            url: [[${basePath}]] + "/member/queryLowerLevel",
            data: {
                ucode: ucode
            },
            success: function (res) {
                if (res.success) {
                    var data = res.data;
                    // 树形组件配置
                    tree.render({
                        elem: '#tree-container',
                        data: data,  // 树形节点数据
                        showLine: false,  // 是否显示连接线
                        onlyIconControl: false,  // 是否仅允许点击图标控制展开和折叠
                        click: function(node) {
                            // 使用 reload 方法重新渲染树形组件
                            tree.reload('tree-container', {
                                data: tree.getData('tree-container')  // 使用当前的数据重新渲染
                            });
                        }
                    });

                } else {
                    layer.msg(res.msg, {icon: 2}, 2000);
                }
            }
        });
        layer.open({
            type: 1,
            title: '下级邀请码',
            area: ['1000px', '450px'],
            content: $('#tree-container'),
            success: function () {
            }
        });
    }

    // 查询实名用户人数
    function queryReal() {
        $.ajax({
            type: "post",
            url: [[${basePath}]] + "/member/queryReal",
            data: {},
            success: function (res) {
                if (res.success) {
                    var data = res.data;
                    $("#realMemberId").text(data);
                } else {
                    layer.msg(res.msg, {icon: 2}, 2000);
                }
            }
        });
    }

    // 查询注册人数
    function queryRegister(day) {
        $.ajax({
            type: "post",
            url: [[${basePath}]] + "/member/queryUserRegister",
            data: {day: day},
            success: function (res) {
                if (res.success) {
                    var data = res.data;
                    var registerCount = data.registerCount;
                    $("#registerMemberId").text(registerCount);
                } else {
                    layer.msg(res.msg, {icon: 2}, 2000);
                }
            }
        });
    }

    function queryUserLogin() {
        var days = $("input[name='days']").val();
        if (days < 1) {
            layer.msg("请输入正确的天数进行查询！", {icon: 2}, 2000);
            return
        }
        $.ajax({
            type: "post",
            url: [[${basePath}]] + "/member/queryUserLogin",
            data: {days: days},
            success: function (res) {
                if (res.success) {
                    var data = res.data;
                    var loginCount = data.loginCount;
                    var loginUserCount = data.loginUserCount;
                    $("#loginCountId").text(loginCount);
                    $("#loginMemberId").text(loginUserCount);
                } else {
                    layer.msg(res.msg, {icon: 2}, 2000);
                }
            }
        });
    }

    // 查看用户详情
    function showUserDetails(userId) {
        var index = layer.open({
            type: 2,
            title: '用户详情',
            shadeClose: true,
            shade: 0.2,
            maxmin: true, //开启最大化最小化按钮
            area: ['1200px', '100%'],
            content: [[${basePath}]] + '/member/list/details?userId=' + userId
        });


        layer.full(index);
    }
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="changeValidStatus"><i class="layui-icon"></i>实名设置</a>
    <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="edit"><i class="layui-icon"></i>用户备注</a>
    <a class="layui-btn layui-btn-xs" lay-event="changePassword"><i class="layui-icon"></i>登录密码</a>
    <a class="layui-btn layui-btn-xs" lay-event="changePayPassword"><i class="layui-icon"></i>支付密码</a>
    <!--<i class="layui-icon layui-icon-password" title="修改登录密码" style="cursor: pointer" lay-event="changePassword"></i>-->
    <!--<i class="layui-icon layui-icon-dollar" title="修改支付密码" style="cursor: pointer" lay-event="changePayPassword"></i>-->
    <!--<i class="layui-icon layui-icon-friends" title="好友列表" style="cursor: pointer" lay-event="friend"></i>-->
    <!--<i class="layui-icon layui-icon-rmb" title="资金明细" style="cursor: pointer" lay-event="fundDetails"></i>-->
    {{#  if(d.status == 0){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="freeze"><i class="layui-icon"></i>用户冻结</a>
    {{#  } else { }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="freeze"><i class="layui-icon"></i>用户解冻</a>
    {{#  } }}
    <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="integral"><i class="layui-icon"></i>增加积分</a>
    <a class="layui-btn layui-btn-xs" lay-event="water"><i class="layui-icon"></i>浇水次数</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="integralDetails"><i class="layui-icon"></i>积分详情</a>
    <!--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="chatRecord"><i class="layui-icon layui-icon-speaker"></i>聊天记录</a>-->
    <!--<i class="layui-icon layui-icon-speaker" title="聊天记录" style="cursor: pointer" lay-event="chatRecord"></i>-->
</script>
</body>
</html>